# -*- coding: utf-8 -*-
import pymysql
import redis
from configparser import ConfigParser
cf = ConfigParser()
cf.read("config.ini")
# cf.read("/home/oyo_admin/ctrip_shengyitong/config.ini")

host = cf.get("Mysql-Database", "host")
port = cf.get("Mysql-Database", "port")
user = cf.get("Mysql-Database", "user")
passwd = cf.get("Mysql-Database", "passwd")
db = cf.get("Mysql-Database", "db")
charset = cf.get("Mysql-Database", "charset")

conn = pymysql.connect(host=host, port=int(port), user=user, passwd=passwd, db=db, charset=charset)
cur = conn.cursor()

host = cf.get("User-Redis-Database", "host")
port = cf.get("User-Redis-Database", "port")
password = cf.get("User-Redis-Database", "password")
db = cf.get("User-Redis-Database", "db")
r = redis.Redis(host=host, port=port, password=password, db=db, charset='utf-8',decode_responses=True)

sql="SELECT max(batch_no) from ota_back_account_info where type=0 and ota_channel_en='ctrip'"
cur.execute(sql)
batch_no=cur.fetchall()
batch_no=batch_no[0][0]

sql="SELECT a.sync_account_id,a.sync_username,a.sync_password from ota_back_account_info as a,ota_back_account_status as b where a.CRS_ID=b.CRS_ID and a.ota_channel_en='ctrip' and a.batch_no='%s' and b.Ctrip_Status=0"%(batch_no)
cur.execute(sql)
datas=cur.fetchall()

for i in datas:
    r.lpush('ctrip_shengyitong_users_21',i)



